package com.hourupdate.network.bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.hourupdate.network.connection.ConnectionJDBC;

public class Running {
	static final Logger logger = Logger.getLogger(Running.class);
	private String cn_id = null;
	private String cdn_id = null;
	private String create_date = null;
	public String getCn_id() {
		return cn_id;
	}
	public void setCn_id(String cn_id) {
		this.cn_id = cn_id;
	}
	public String getCdn_id() {
		return cdn_id;
	}
	public void setCdn_id(String cdn_id) {
		this.cdn_id = cdn_id;
	}
	public String getCreate_date() {
		return create_date;
	}
	public void setCreate_date(String create_date) {
		this.create_date = create_date;
	}
	public boolean insertPreparedStatement(Connection conn){
		String sql = "INSERT INTO "+ConnectionJDBC.schema+"."+ConnectionJDBC.schemaRUNNING+
				"(" +
				"CN_ID,"+
				"CDN_ID,"+
				"CREATE_DATE" +
				")"+
				"VALUES"+
				"("+
				"?,"+
				"?,"+
				"?"+
				")";
		boolean success = false;
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ExecuteSQLBean eb = new ExecuteSQLBean();
			ps.setString(1, this.getCn_id());
			ps.setString(2, this.getCdn_id());
			ps.setString(3, this.getCreate_date());
			success = eb.executeStatement(ps);
			ps.close();
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}
		return success;
	}
	public boolean updatePreparedStatement(Connection conn){
		String sql = "UPDATE "+ConnectionJDBC.schema+"."+ConnectionJDBC.schemaRUNNING+" "+
				"SET "+
				"CDN_ID = ? "+
				"WHERE "+
				"CN_ID = ? "+
				"AND CREATE_DATE = ?";
		boolean success = false;
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ExecuteSQLBean eb = new ExecuteSQLBean();
			ps.setString(1, this.getCdn_id());
			ps.setString(2, this.getCn_id());
			ps.setString(3, this.getCreate_date());
			success = eb.executeStatement(ps);
			ps.close();
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}
		return success;
	}
}
